{include file="/sum/common/script" /}

<style>
    .activity-tag {
        padding: 3px 8px;
        border-radius: 10px;
        line-height: 14px;
        font-size: 12px;
        font-weight: 400;
        margin-right: 8px;
        cursor: pointer;
    }

    .activity-tag:last-of-type {
        margin-right: 0;
    }

    .activity-tag.groupon,
    .activity-tag.groupon_ladder {
        color: var(--el-color-primary);
        background: var(--t-bg-active);
    }

    .goods-index .goods-item .goods-image {
        margin-right: 12px;
    }

    .goods-index .goods-item .goods-title {
        height: 20px;
        line-height: 20px;
        font-size: 14px;
        font-weight: 500;
        color: var(--sa-font);
    }

    .goods-index .goods-item .goods-subtitle {
        height: 16px;
        line-height: 16px;
        font-size: 12px;
        font-weight: 400;
        color: var(--sa-subfont);
        margin-bottom: 6px;
    }

    .goods-index .activity-tag.promos {
        color: #faad14;
        background: rgba(250, 173, 20, 0.16);
    }
</style>

<div id="index" class="goods-index panel panel-default panel-intro" v-cloak>
    <el-container class="panel-block">
        <el-header class="sa-header">
            <el-tabs class="sa-tabs" v-model="state.filter.data.type" @tab-change="onChangeTab">
                <el-tab-pane v-for="item in type.data.type" :key="item" :label="item.name" :name="item.type">
                </el-tab-pane>
            </el-tabs>

            <div class="sa-title sa-flex sa-row-between">
                <div class="sa-title-left">
                    <div class="left-name">套餐管理</div>
                    <sa-filter-condition v-model="state.filter" @filter-delete="onChangeFilter">
                    </sa-filter-condition>
                </div>
                <div class="sa-title-right">
                    <el-button class="sa-button-refresh" icon="RefreshRight" @click="getData"></el-button>
                    <el-button class="sa-button-refresh" icon="Search" @click="onOpenFilter"></el-button>

                    {if $auth->check('sum/trade/rule/add')}
                    <el-button icon="Plus" type="primary" @click="onAdd">新增</el-button>
                    {/if}
                </div>
            </div>
        </el-header>
        <el-main class="sa-main">
            <el-table height="100%" class="sa-table" :data="state.data" stripe @selection-change="onChangeSelection"
                @sort-change="onChangeSort">
                <el-table-column type="selection" width="48" align="center"></el-table-column>
                <el-table-column prop="id" label="ID" min-width="90" sortable="custom"> </el-table-column>

                <el-table-column label="类型" min-width="100">
                    <template #default="scope">
                        <el-tag :type="scope.row.type == 'recharge' ? 'primary' : 'warning'">
                            {{ scope.row.type_text }}
                        </el-tag>
                    </template>
                </el-table-column>

                <el-table-column label="标题" min-width="120">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.title || '-' }}
                        </div>
                    </template>
                </el-table-column>

                <el-table-column label="价格" min-width="120" sortable="custom">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.price || '-' }}
                        </div>
                    </template>
                </el-table-column>

                <el-table-column label="金币" min-width="120" sortable="custom">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.score || '-' }}
                        </div>
                    </template>
                </el-table-column>

                <el-table-column label="天数" min-width="120" sortable="custom">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.days || '-' }}
                        </div>
                    </template>
                </el-table-column>

                <el-table-column label="状态" min-width="100">
                    <template #default="scope">
                        <el-tag :type="scope.row.status == 'normal' ? 'success' : 'info'">
                            {{ scope.row.status_text }}
                        </el-tag>
                    </template>
                </el-table-column>

<!--                <el-table-column label="权重" min-width="100" sortable="custom">-->
<!--                    <template #default="scope">-->
<!--                        <div class="sa-table-line-1">-->
<!--                            {{ scope.row.weigh || '-' }}-->
<!--                        </div>-->
<!--                    </template>-->
<!--                </el-table-column>-->

                <el-table-column fixed="right" label="操作" min-width="180">
                    <template #default="scope">
                        {if $auth->check('sum/trade/rule/edit')}
                        <el-button type="primary" link @click="onEdit(scope.row.id)">编辑</el-button>
                        {/if}
                        <el-popconfirm width="fit-content" confirm-button-text="确认" cancel-button-text="取消"
                            title="确认删除这条记录?" @confirm="onDelete(scope.row.id)">
                            <template #reference>
                                {if $auth->check('sum/trade/rule/delete')}
                                <el-button type="danger" link>删除</el-button>
                                {/if}
                            </template>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </el-table>
        </el-main>
        <el-footer class="sa-footer sa-flex sa-row-right">
            <sa-pagination v-model="pagination" @pagination-change="getData"></sa-pagination>
        </el-footer>
    </el-container>
    <sa-filter v-model="state.filter" @filter-change="onChangeFilter"></sa-filter>
</div>